package com.fjh.springboot_01.mapper;

import com.fjh.springboot_01.pojo.Feedback;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface FeedbackMapper {
    
    // 添加留言反馈
    @Insert("INSERT INTO feedback(user_id, username, content, contact_info, status, create_time, update_time) " +
            "VALUES(#{userId}, #{username}, #{content}, #{contactInfo}, 0, NOW(), NOW())")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void add(Feedback feedback);
    
    // 根据用户ID查询留言反馈列表
    @Select("SELECT * FROM feedback WHERE user_id = #{userId} ORDER BY create_time DESC")
    List<Feedback> findByUserId(Integer userId);
    
    // 查询所有留言反馈
    @Select("SELECT * FROM feedback ORDER BY status ASC, create_time DESC")
    List<Feedback> findAll();
    
    // 根据ID查询留言反馈
    @Select("SELECT * FROM feedback WHERE id = #{id}")
    Feedback findById(Integer id);
    
    // 回复留言反馈
    @Update("UPDATE feedback SET reply = #{reply}, reply_user_id = #{replyUserId}, " +
            "reply_username = #{replyUsername}, status = 1, update_time = NOW(), reply_time = NOW() " +
            "WHERE id = #{id}")
    void reply(Feedback feedback);
    
    // 删除留言反馈
    @Delete("DELETE FROM feedback WHERE id = #{id}")
    void deleteById(Integer id);
} 